home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 June / PCFJune.iso / mweb / MWEB Utils / ws295sdk.exe / Ws2sdkzp.exe / SAMPLES / LAYERED / TRACE.H < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-06  |  7.2 KB  |  162 lines

  1. /*++
  2.  
  3.      Copyright c 1996 Intel Corporation
  4.      All Rights Reserved
  5.  
  6.      Permission is granted to use, copy and distribute this software and
  7.      its documentation for any purpose and without fee, provided, that
  8.      the above copyright notice and this statement appear in all copies.
  9.      Intel makes no representations about the suitability of this
  10.      software for any purpose.  This software is provided "AS IS."
  11.  
  12.      Intel specifically disclaims all warranties, express or implied,
  13.      and all liability, including consequential and other indirect
  14.      damages, for the use of this software, including liability for
  15.      infringement of any proprietary rights, and including the
  16.      warranties of merchantability and fitness for a particular purpose.
  17.      Intel does not assume any responsibility for any errors which may
  18.      appear in this software nor any responsibility to update it.
  19.  
  20. Module Name:
  21.  
  22.     SPI.CPP :
  23.  
  24. Abstract:
  25.  
  26.     This file defines a macros for tracing and the function prototypes for the
  27.     actual output functions. If the symbol TRACING is not defined  all the
  28.     macros expands to ((void)0).
  29.  
  30.     There are three global variables that control the behavior of the tracing
  31.     macros/functions.  debugLevel is a 32 bit bitmask that determine controls
  32.     what level of debug messages is output. iTraceDestination controls whether
  33.     the debug output goes to a file or to the aux device. if iTraceDestination
  34.     == TRACE_TO_FILE szTraceFile must contain the filename.
  35.  
  36.  
  37. --*/
  38.  
  39. #ifndef __TRACE_H__
  40. #define __TRACE_H__
  41.  
  42. extern
  43. #if defined(__cplusplus)
  44. "C"
  45. #endif  // defined(__cplusplus)
  46. VOID PrintDebugString(char *format, ...);
  47.  
  48. //
  49. // defines for where the debug output should go
  50. //
  51. #define TRACE_TO_FILE    0
  52. #define TRACE_TO_AUX     1
  53.  
  54. // the size of the string buffers used as arg to wsprintf
  55. // in trace.c
  56. #define TRACE_OUTPUT_BUFFER_SIZE  1024
  57.  
  58. // Debug level masks
  59. #define DBG_TRACE       0x00000001
  60. #define DBG_WARN        0x00000002
  61. #define DBG_ERR         0x00000004
  62. #define DBG_MEMORY      0x00000008
  63. #define DBG_LIST        0x00000010
  64. #define DBG_FUNCTION    0x00000020
  65.  
  66. #if defined(TRACING)
  67.  
  68. extern
  69. #if defined(__cplusplus)
  70. "C"
  71. #endif  // defined(__cplusplus)
  72. DWORD debugLevel;
  73.  
  74. //
  75. // This macro creates debug output depending on the debug mask "sev" and
  76. // calls PrintDebugString output function. PrintDebugString makes the
  77. // descision on whether the output goes into a file or to the aux device.
  78. //
  79. #define  DEBUGF(sev, var_args)                                                \
  80. {                                                                             \
  81.    if ((sev) & debugLevel) {                                                  \
  82.       switch (sev) {                                                          \
  83.          case DBG_TRACE:                                                      \
  84.             PrintDebugString("-| TRACE   :: ");                               \
  85.             PrintDebugString(" %s : %d |-\n", __FILE__, __LINE__ );           \
  86.             PrintDebugString var_args ;                                       \
  87.          break;                                                               \
  88.          case DBG_WARN:                                                       \
  89.             PrintDebugString("-| WARNING :: ");                               \
  90.             PrintDebugString(" %s : %d |-\n", __FILE__, __LINE__ );           \
  91.             PrintDebugString var_args ;                                       \
  92.             break;                                                            \
  93.          case DBG_ERR:                                                        \
  94.             PrintDebugString("-| ERROR   :: ");                               \
  95.             PrintDebugString(" %s : %d |-\n", __FILE__, __LINE__ );           \
  96.             PrintDebugString var_args;                                        \
  97.             break;                                                            \
  98.         case DBG_MEMORY:                                                      \
  99.             PrintDebugString("-| MEMORY  :: ");                               \
  100.             PrintDebugString(" %s : %d |-\n", __FILE__, __LINE__ );           \
  101.             PrintDebugString var_args ;                                       \
  102.             break;                                                            \
  103.         case DBG_LIST:                                                        \
  104.             PrintDebugString("-| LIST    :: ");                               \
  105.             PrintDebugString(" %s : %d |-\n", __FILE__, __LINE__ );\
  106.             PrintDebugString var_args ;                                       \
  107.             break;                                                            \
  108.         case DBG_FUNCTION:                                                    \
  109.             PrintDebugString var_args;                                        \
  110.             break;                                                            \
  111.       }                                                                       \
  112.    }                                                                          \
  113. }                                                                             \
  114.  
  115.  
  116.  
  117. #define ALLOC_LOG( pointer, size)                                             \
  118.     DEBUGF( DBG_MEMORY ,("MEMORY %lX size %X Allocated \n",                   \
  119.                          (pointer),(size)))                                   \
  120.  
  121. #define DEALLOC_LOG(pointer, size)                                            \
  122. DEBUGF( DBG_MEMORY ,("MEMORY %lX size %X Deallocated \n",                     \
  123.                          (pointer),(size)))                                   \
  124.  
  125.  
  126. #define LIST_ADD_LOG(list, element)                                           \
  127.     DEBUGF( DBG_LIST ,("LIST %lX element %lX Added \n",                       \
  128.                        (list),(element)))                                     \
  129.  
  130. #define LIST_DEL_LOG(list, element)                                           \
  131.     DEBUGF( DBG_LIST ,("LIST %lX element %lX Deleted \n",                     \
  132.                        (list),(element)))                                     \
  133.  
  134. #define ENTER_FUNCTION(name)                                                  \
  135. DEBUGF( DBG_FUNCTION,name)                                \
  136.  
  137.  
  138. #define EXIT_FUNCTION(name)                                                   \
  139. DEBUGF( DBG_FUNCTION,name)                                \
  140.  
  141.  
  142. #else // TRACING
  143.      // make sure that these are defined if tracing is turned off
  144. #define DEBUGF(sev, va)                     ((void)0)
  145. #define LIST_ADD_LOG(list, element)         ((void)0)
  146. #define LIST_DEL_LOG(list, element)         ((void)0)
  147. #define ENTER_FUNCTION(name)                ((void)0)
  148. #define EXIT_FUNCTION(name)                 ((void)0)
  149. #define ALLOC_LOG( pointer, size)                                             \
  150.     DEBUGF( DBG_MEMORY ,("",                                                  \
  151.                          (pointer),(size)))                                   \
  152.  
  153. #define DEALLOC_LOG(pointer, size)\
  154.     DEBUGF( DBG_MEMORY ,("",\
  155.                          (pointer),(size)))  \
  156.  
  157. #endif // TRACING
  158.  
  159. #endif // __TRACE_H__
  160.  
  161.  
  162.